package com.flyemu.share.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.flyemu.share.annotation.SaAdminId;
import com.flyemu.share.annotation.SaMerchantId;
import com.flyemu.share.annotation.SaOrganizationId;
import com.flyemu.share.entity.RelationAccount;
import com.flyemu.share.service.RelationAccountService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/relationAccount")
@RequiredArgsConstructor
@SaCheckLogin
public class RelationAccountController {
    private final RelationAccountService relationAccountService;
    /**
     * 保存或更新关联信息
     *
     * @param relationAccount
     * @return
     */
    @PostMapping
    public JsonResult save(@RequestBody @Valid RelationAccount relationAccount, @SaMerchantId Long merchantId, @SaOrganizationId Long organizationId, @SaAdminId Long adminId) {
        relationAccount.setMerchantId(merchantId);
        relationAccount.setAdminId(adminId);
        relationAccount.setOrganizationId(organizationId);
        relationAccountService.save(relationAccount);

        return JsonResult.successful();
    }

    /**
     * 获取
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public JsonResult load(@PathVariable Long id, @SaMerchantId Long merchantId, @SaOrganizationId Long organizationId) {
        RelationAccount relationAccount =  relationAccountService.loadById(id,merchantId,organizationId);
        relationAccount.setPassword(null);
        return JsonResult.successful(relationAccount);
    }

}
